package com.server.core;

import lombok.AllArgsConstructor;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
 * @author WuFengSheng
 * @date 2025/4/19 10:01
 */
@Configuration
@AllArgsConstructor
public class ToolCallbackProviderConfig {

    private final ApplicationContext applicationContext;

    @Bean
    public ToolCallbackProvider methodToolCallbackProvider() {
        Map<String, McpTool> mcpBeanMap = applicationContext.getBeansOfType(McpTool.class);
        return MethodToolCallbackProvider.builder()
                .toolObjects(mcpBeanMap.values().toArray())
                .build();
    }

}
